package com.fastloan.core.shiro;

import com.fastloan.mgt.customer.model.ZyCustomer;
import com.fastloan.mgt.customer.service.ZyCustomerService;
import com.fastloan.safe.mgt.login.service.impl.LoginServiceImpl;
import com.fastloan.safe.mgt.user.model.CmuUser;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author rankai
 *         createTime 2017-11-2017/11/9 16:19
 */
public class MyLoginServiceImpl extends LoginServiceImpl {

    @Autowired
    private ZyCustomerService customerService;

    @Override
    public CmuUser selectByPhone(String s) {
        CmuUser cmuUser = super.selectByPhone(s);
        if (cmuUser == null) {
            ZyCustomer zyCustomer = customerService.selectOne(new ZyCustomer().setPhoneNum(s));
            if (zyCustomer == null) {
                return null;
            } else {
                cmuUser = new CmuUser();
                cmuUser.setId(zyCustomer.getId());
                cmuUser.setPhone(zyCustomer.getPhoneNum());
                cmuUser.setStatus(0);
                return cmuUser;
            }
        }
        return cmuUser;
    }
}
